<?php
/* This file is part of a copyrighted work; it is distributed with NO WARRANTY.
 * See the file COPYRIGHT.html for more details.
 */
 
  require_once("../shared/common.php");
  $tab = "school";
  $nav = "view";
  $helpPage = "schoolView";
  $focus_form_name = "barcodesearch";
  $focus_form_field = "cue";

  require_once("../functions/inputFuncs.php");
  require_once("../functions/formatFuncs.php");
  require_once("../shared/logincheck.php");
  require_once("../classes/School.php");
  require_once("../classes/SchoolQuery.php");
  require_once("../classes/SectionSearchQuery.php");
  require_once("../classes/DmQuery.php");
  require_once("../shared/get_form_vars.php");
  require_once("../classes/Localize.php");
  $loc = new Localize(OBIB_LOCALE,$tab);

  #****************************************************************************
  #*  Checking for get vars.  Go back to form if none found.
  #****************************************************************************
  if (count($_GET) == 0) {
    header("Location: ../school/index.php");
    exit();
  }

  #****************************************************************************
  #*  Retrieving get var
  #****************************************************************************
  $schoolid = $_GET["schoolid"];
  if (isset($_GET["msg"])) {
    $msg = "<font class=\"error\">".H($_GET["msg"])."</font><br><br>";
  } else {
    $msg = "";
  }

  #****************************************************************************
  #*  Loading a few domain tables into associative arrays
  #****************************************************************************
  $dmQ = new DmQuery();
  $dmQ->connect();
  $stateDm = $dmQ->getAssoc('state_dm');
  $areaDm = $dmQ->getAssoc('area_dm');
  $cityDm = $dmQ->getAssoc('city_dm');
  $departamentDm = $dmQ->getAssoc('departament_dm');
  $turnoDm = $dmQ->getAssoc('turno_dm');
  $dmQ->close();

  #****************************************************************************
  #*  Search database for School
  #****************************************************************************
  $schoolQ = new SchoolQuery();
  $schoolQ->connect();
  $school = $schoolQ->get($schoolid);
  $schoolQ->close();


  #**************************************************************************
  #*  Show School information
  #**************************************************************************
  require_once("../shared/header.php");
?>

<?php echo $balMsg ?>
<?php echo $msg ?>

<table class="primary">
  <tr>
    <th align="left" colspan="2" nowrap="yes">
      <?php echo $loc->getText("schoolViewHead1"); ?>
    </th>
  </tr>
  <tr>
    <td nowrap="true" class="primary" valign="top">
      <?php echo $loc->getText("schoolName"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($school->getName());?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewCue"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($school->getCue());?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewAddress"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($school->getAddress());?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewAnexee"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($school->getAnexee());?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewEst"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($school->getEst());?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewPhone"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($school->getPhone());?>
    </td>
  </tr>  
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewArea"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($areaDm[$school->getAreaId()]);?>
    </td>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewCity"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($cityDm[$school->getCityId()]);?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewDepartament"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($departamentDm[$school->getDepartamentId()]);?>
    </td>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php echo $loc->getText("schoolViewState"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo H($stateDm[$school->getStateId()]);?>
    </td>
  </tr>  

</table>

<h1><?php echo $loc->getText("schoolViewHead4"); ?> 
  <font class="primary">
  <a href="../school/section_new_form.php?schoolid=<?php echo HURL($schoolid); ?>">[Agregar Seccion]</a>
  </font>
</h1>
<table class="primary">
  <tr>
    <th valign="top" nowrap="yes" align="left">
      <?php echo $loc->getText("schoolViewOutHdr2"); ?>
    </th>  
    <th valign="top" nowrap="yes" align="left">
      <?php echo $loc->getText("schoolViewOutHdr1"); ?>
    </th>
    <th valign="top" nowrap="yes" align="left">
      <?php echo $loc->getText("schoolViewOutHdr3"); ?>
    </th>
    <th valign="top" nowrap="yes" align="left">
      <?php echo $loc->getText("schoolViewOutHdr4"); ?>
    </th>
    <th valign="top" nowrap="yes" align="left">
      <?php echo $loc->getText("schoolViewOutHdr5"); ?>
    </th>
    <th valign="top" nowrap="yes" align="left">
      <?php echo $loc->getText("schoolViewOutHdr6"); ?>
    </th>
    <th valign="top" nowrap="yes" align="left">

    </th>
    <th valign="top" nowrap="yes" align="left">

    </th>
  </tr>

<?php
  #****************************************************************************
  #*  Search database for BiblioStatus data
  #****************************************************************************
  $sectionQ = new SectionSearchQuery();
  $sectionQ->connect();
  if ($sectionQ->errorOccurred()) {
    $sectionQ->close();
    displayErrorPage($sectionQ);
  }
  if (!$sectionQ->doQuery($schoolid)) {
    $sectionQ->close();
    displayErrorPage($sectionQ);
  }
  if ($sectionQ->getRowCount() == 0) {
?>
  <tr>
    <td class="primary" align="center" colspan="8">
      <?php echo $loc->getText("schoolViewNoCheckouts"); ?>
    </td>
  </tr>
<?php
  } else {
    while ($section = $sectionQ->fetchRow()) {
?>
  <tr>
    <td class="primary" valign="top">
      <?php echo H($section->getYear());?>
    </td>  
    <td class="primary" valign="top" nowrap="yes">
      <?php echo H($section->getName());?>
    </td>
    <td class="primary" valign="top" >
      <?php echo H($turnoDm[$section->getTurnoId()]);?>
    </td>
    <td class="primary" valign="top" >
      <?php echo H($section->getStudents());?>
    </td>
    <td class="primary" valign="top" >
      <?php echo H($section->getApply());?>
    </td>
    <td class="primary" valign="top" >
      <?php echo H($section->getClaveOne());?>
    </td>
    <td class="primary" valign="top" >
      <a href="../school/section_edit_form.php?sectionid=<?php echo HURL($section->getSectionId());?>">Editar</a>
    </td>
    <td class="primary" valign="top" >
      <a href="../school/section_del_confirm.php?sectionid=<?php echo HURL($section->getSectionId());?>">Eliminar</a>
    </td>        
  </tr>
<?php
    }
  }
  $sectionQ->close();
?>

</table>



<?php require_once("../shared/footer.php"); ?>
